package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;
import com.yitiao.data_algorithms.leetcode.editor.cn.base.TreeNode;

class SingleNumberIii {
    // 2022-08-26 13:24:00
    public static void main(String[] args) {
        Solution solution = new SingleNumberIii().new Solution();
    }

    //leetcode submit region begin(Prohibit modification and deletion)
    class Solution {
        public int[] singleNumber(int[] nums) {

            int sum = 0;
            for (int j : nums) {
                sum ^= j;
            }
            int lowbit = lowbit(sum);
            int num1 = 0;
            int num2 = 0;
            for (int num : nums) {
                if ((lowbit & num) == 0)
                    num1 ^= num;
                else
                    num2 ^= num;
            }
            return new int[]{num1, num2};
        }

        int lowbit(int n) {
            return n & (-n);
        }
    }
//leetcode submit region end(Prohibit modification and deletion)

}